package com.xuecheng.order.controller;


import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.xuecheng.commons.model.dto.OrdersDto;
import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.vo.OrdersVo;
import com.xuecheng.commons.model.dto.OrdersDto;
import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.vo.ResponseResult;
import lombok.Data;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.order.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <p>
 * 订单前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
public class OrdersController {

    @Autowired
    private OrdersService  ordersService;


    // 用户下单
    @PostMapping("/orders/create/{coursePubId}")
    public ResponseResult createOrder(@PathVariable("coursePubId")Long coursePubId){
        return ordersService.createOrder(coursePubId);
    }

    // 查询支付结果
    @GetMapping("/orders/{orderNo}")
    public ResponseResult findPay(@PathVariable("orderNo") String orderNo){
        return ordersService.findPay(orderNo);
    }

    // 机构的订单列表及明细
    @PostMapping("/orders/org-list")
    public ResponseResult findPage(PageRequest params, @RequestBody OrdersDto dto) { // 接受参数
        // 2,返回结果
        return ordersService.findPage(params,dto);
    }

    // excel导出
    @GetMapping("orders/order/excel")
    public ResponseResult indexWrite(Long companyId) {
        //调用service
        return ordersService.indexWrite(companyId);

    }






    //分页查询用户的个人订单信息
    @PostMapping("/orders/my-list")
    public ResponseResult findByPage(PageRequest request, @RequestBody OrdersDto dto){
        return ordersService.findByPage(request,dto);
    }
}
